package com.study.a12waitandnotify;

public class Cook extends Thread {
    //套路
    //1.循环
    //2.同步代码块
    //3.判断共享数据是否到了末尾
    //4.判断共享数据是否到了末尾（没有到末尾执行核心逻辑）
    //
    @Override
    public void run() {
       while(true){
           synchronized (Desk.lock){
               if(Desk.count==0){
                   break;
               }else{
                   if(Desk.foodFlag==1){
                       try {
                           Desk.lock.wait();
                       } catch (InterruptedException e) {
                           throw new RuntimeException(e);
                       }
                   }else{
                       System.out.println("厨师在做第" + Desk.count + "道菜");
                       //修改桌子状态
                       Desk.foodFlag=1;
                       //唤醒顾客
                       Desk.lock.notifyAll();
                   }
               }
           }
       }
    }
}
